//
//  SuperMarketViewController.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/19.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "SuperMarketViewController.h"
#import "SuperMarketViewModel.h"
#import "GoodsOrStoreNavView.h"
#import "SupermarketStellModel.h"
#import "HightQualityStoreModel.h"
#import "StoreInformationViewController.h"
#import "GoodsInformationViewController.h"

@interface SuperMarketViewController ()<SuperMarketStellDelegate>
{
    SupermarketStellModel * marketModel;
}
@property (nonatomic,strong)SuperMarketViewModel * superViewModel;
@end

@implementation SuperMarketViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#F2F2F2"];
    self.navigationItem.titleView = [self createTitView];
    self.superViewModel = [[SuperMarketViewModel alloc] initWithViewToViewModel:self.tableView theSuperView:self.view];
    self.superViewModel.delegate = self;
    [self headerRereshing];
}

-(UIView *)createTitView{
    GoodsOrStoreNavView * titleView = [[GoodsOrStoreNavView alloc] initWithFrame:CGRectMake(0, 0, kWidthProportion_In_iPhoneTriploid(295), kHeightProportion_In_iPhoneTriploid(30))];
    return titleView;
}

-(void)headerRereshing{
    self.page = 1;
    [self loadData];
}

-(void)footerRereshing{
    if (self.page < marketModel.data.pages) {
        self.page ++;
        [self loadData];
    }else{
        [GLGWProgressHUD showNotice:@"没有更多钢材了！" view:nil];
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
    }
}

-(void)loadData{
    @weakify(self)
    [[self.superViewModel.market_recommendCommand execute:[NSNumber numberWithInteger:self.page]]subscribeNext:^(id x) {
        @strongify(self)
        self->marketModel = (SupermarketStellModel *)x;
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
    }error:^(NSError *error) {
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
    }];
}

#pragma mark -- SuperMarketStellDelegate
-(void)chickeStore:(SupermarketStellModel_Infos *)infor_model theStoreType:(StoreOrGoodsInfor)s_type{
    if (s_type == StoreOrGoodsInfor_Store) {
        HightQualityStoreModel_Infos * hightModel = [HightQualityStoreModel_Infos new];
        hightModel.store_id = infor_model.shopId;
        hightModel.shopName = infor_model.shopName;
        StoreInformationViewController * storeVC = [StoreInformationViewController new];
        storeVC.qua_Model = hightModel;
        [self.navigationController pushViewController:storeVC animated:YES];
    }else{
        GoodsInformationViewController * goodsInforVc = [GoodsInformationViewController new];
        goodsInforVc.goods_id = infor_model.productId;
        [self.navigationController pushViewController:goodsInforVc animated:YES];
    }
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
